using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Xml;
using System.Collections;
using ACFramework;

namespace ACSeguridad
{
	public partial class EUsuarios
	{
		#region Campos
		
		private Int32 m_user_iduser;
		private String m_nive_codigo;
		private String m_grup_codigo;
		private String m_user_codusr;
		private String m_user_nombre;
		private String m_user_dni;
		private String m_user_desc;
		private String m_user_passusr;
		private Boolean m_user_activo;
		private String m_user_mail;
		private String m_user_usrcrea;
		private DateTime m_user_feccrea;
		private String m_user_usrmod;
		private DateTime m_user_fecmod;
		private Boolean m_nuevo;
		private Boolean m_modificado;
		private Boolean m_eliminado;

		private Hashtable m_hash;
		
		#endregion

		#region Constructores
		
			/// <summary>
			/// Inicializar una nueva instancia de la clase EUsuarios.
			/// </summary>
		public EUsuarios()
		{
			try
			{
				Object _obj = ACSeguridad.Properties.Resources.xmlUsuarios;
				XmlDocument _xml = new XmlDocument();
				_xml.LoadXml(_obj.ToString());
				if (m_hash == null) 
				{
					m_hash = new Hashtable();
					XmlNodeList cPlantilla = _xml.GetElementsByTagName("Tabla");
					XmlNodeList cCampos = ((XmlElement)cPlantilla[0]).GetElementsByTagName("Campos");
					XmlNodeList Campo = ((XmlElement)cCampos[0]).GetElementsByTagName("CCampo");
					foreach(XmlElement Item in Campo)
					{
						m_hash.Add(Item.InnerText.ToString(), new CCampo(Item.GetAttribute("xmlns"), (Item.GetAttribute("Identity") == "1"? true : false), (Item.GetAttribute("ForeignKey") == "1"? true : false), (Item.GetAttribute("PrimaryKey") == "1"? true : false)));
					}
				}
			}
			catch(Exception ex)
			{
				throw ex;
			}
		}

		#endregion

		#region Propiedades
		
		/// <summary>
		/// Gets or sets el valor de: USER_IdUser.
		/// </summary>
		public Int32 USER_IdUser
		{
			get { return m_user_iduser; }
			set
			{
				if (m_user_iduser != null)
				{
					if (m_user_iduser != value)
					{
						m_user_iduser = value;
						OnUSER_IdUserChanged(m_user_iduser, EventArgs.Empty);
					}
				}
				else
				{
					m_user_iduser = value;
					OnUSER_IdUserChanged(m_user_iduser, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: NIVE_Codigo.
		/// </summary>
		public String NIVE_Codigo
		{
			get { return m_nive_codigo; }
			set
			{
				if (m_nive_codigo != null)
				{
					if (m_nive_codigo != value)
					{
						m_nive_codigo = value;
						OnNIVE_CodigoChanged(m_nive_codigo, EventArgs.Empty);
					}
				}
				else
				{
					m_nive_codigo = value;
					OnNIVE_CodigoChanged(m_nive_codigo, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: GRUP_Codigo.
		/// </summary>
		public String GRUP_Codigo
		{
			get { return m_grup_codigo; }
			set
			{
				if (m_grup_codigo != null)
				{
					if (m_grup_codigo != value)
					{
						m_grup_codigo = value;
						OnGRUP_CodigoChanged(m_grup_codigo, EventArgs.Empty);
					}
				}
				else
				{
					m_grup_codigo = value;
					OnGRUP_CodigoChanged(m_grup_codigo, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_CodUsr.
		/// </summary>
		public String USER_CodUsr
		{
			get { return m_user_codusr; }
			set
			{
				if (m_user_codusr != null)
				{
					if (m_user_codusr != value)
					{
						m_user_codusr = value;
						OnUSER_CodUsrChanged(m_user_codusr, EventArgs.Empty);
					}
				}
				else
				{
					m_user_codusr = value;
					OnUSER_CodUsrChanged(m_user_codusr, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_Nombre.
		/// </summary>
		public String USER_Nombre
		{
			get { return m_user_nombre; }
			set
			{
				if (m_user_nombre != null)
				{
					if (m_user_nombre != value)
					{
						m_user_nombre = value;
						OnUSER_NombreChanged(m_user_nombre, EventArgs.Empty);
					}
				}
				else
				{
					m_user_nombre = value;
					OnUSER_NombreChanged(m_user_nombre, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_DNI.
		/// </summary>
		public String USER_DNI
		{
			get { return m_user_dni; }
			set
			{
				if (m_user_dni != null)
				{
					if (m_user_dni != value)
					{
						m_user_dni = value;
						OnUSER_DNIChanged(m_user_dni, EventArgs.Empty);
					}
				}
				else
				{
					m_user_dni = value;
					OnUSER_DNIChanged(m_user_dni, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_Desc.
		/// </summary>
		public String USER_Desc
		{
			get { return m_user_desc; }
			set
			{
				if (m_user_desc != null)
				{
					if (m_user_desc != value)
					{
						m_user_desc = value;
						OnUSER_DescChanged(m_user_desc, EventArgs.Empty);
					}
				}
				else
				{
					m_user_desc = value;
					OnUSER_DescChanged(m_user_desc, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_PassUsr.
		/// </summary>
		public String USER_PassUsr
		{
			get { return m_user_passusr; }
			set
			{
				if (m_user_passusr != null)
				{
					if (m_user_passusr != value)
					{
						m_user_passusr = value;
						OnUSER_PassUsrChanged(m_user_passusr, EventArgs.Empty);
					}
				}
				else
				{
					m_user_passusr = value;
					OnUSER_PassUsrChanged(m_user_passusr, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_Activo.
		/// </summary>
		public Boolean USER_Activo
		{
			get { return m_user_activo; }
			set
			{
				if (!m_user_activo.Equals(value))
				{
					m_user_activo = value;
					OnUSER_ActivoChanged(m_user_activo, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_Mail.
		/// </summary>
		public String USER_Mail
		{
			get { return m_user_mail; }
			set
			{
				if (m_user_mail != null)
				{
					if (m_user_mail != value)
					{
						m_user_mail = value;
						OnUSER_MailChanged(m_user_mail, EventArgs.Empty);
					}
				}
				else
				{
					m_user_mail = value;
					OnUSER_MailChanged(m_user_mail, EventArgs.Empty);
				}
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_UsrCrea.
		/// </summary>
		public String USER_UsrCrea
		{
			get { return m_user_usrcrea; }
			set
			{
				if (m_user_usrcrea != value)
				{ m_user_usrcrea = value; }
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_FecCrea.
		/// </summary>
		public DateTime USER_FecCrea
		{
			get { return m_user_feccrea; }
			set
			{
				if (m_user_feccrea != value)
				{ m_user_feccrea = value; }
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_UsrMod.
		/// </summary>
		public String USER_UsrMod
		{
			get { return m_user_usrmod; }
			set
			{
				if (m_user_usrmod != value)
				{ m_user_usrmod = value; }
			}
		}
		/// <summary>
		/// Gets or sets el valor de: USER_FecMod.
		/// </summary>
		public DateTime USER_FecMod
		{
			get { return m_user_fecmod; }
			set
			{
				if (m_user_fecmod != value)
				{ m_user_fecmod = value; }
			}
		}
		/// <summary>
		/// Gets Nuevo.
		/// </summary>
		public Boolean Nuevo
		{
			get { return m_nuevo; }
		}
		/// <summary>
		/// Gets Modificado.
		/// </summary>
		public Boolean Modificado
		{
			get { return m_modificado; }
		}
		/// <summary>
		/// Gets Eliminado.
		/// </summary>
		public Boolean Eliminado
		{
			get { return m_eliminado; }
		}
		public Hashtable Hash
		{
			get{ return m_hash;  }
		}
		public static String Tabla
		{
			get{ return "Usuarios"; }
		}
		public static String Esquema
		{
			get{ return "dbo"; }
		}

		
		#endregion

		#region Eventos
		
		public event EventHandler USER_IdUserChanged;
		public event EventHandler NIVE_CodigoChanged;
		public event EventHandler GRUP_CodigoChanged;
		public event EventHandler USER_CodUsrChanged;
		public event EventHandler USER_NombreChanged;
		public event EventHandler USER_DNIChanged;
		public event EventHandler USER_DescChanged;
		public event EventHandler USER_PassUsrChanged;
		public event EventHandler USER_ActivoChanged;
		public event EventHandler USER_MailChanged;

		protected void OnUSER_IdUserChanged(Object sender, EventArgs e)
		{
			if (USER_IdUserChanged != null)
			{
				USER_IdUserChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnNIVE_CodigoChanged(Object sender, EventArgs e)
		{
			if (NIVE_CodigoChanged != null)
			{
				NIVE_CodigoChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnGRUP_CodigoChanged(Object sender, EventArgs e)
		{
			if (GRUP_CodigoChanged != null)
			{
				GRUP_CodigoChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_CodUsrChanged(Object sender, EventArgs e)
		{
			if (USER_CodUsrChanged != null)
			{
				USER_CodUsrChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_NombreChanged(Object sender, EventArgs e)
		{
			if (USER_NombreChanged != null)
			{
				USER_NombreChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_DNIChanged(Object sender, EventArgs e)
		{
			if (USER_DNIChanged != null)
			{
				USER_DNIChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_DescChanged(Object sender, EventArgs e)
		{
			if (USER_DescChanged != null)
			{
				USER_DescChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_PassUsrChanged(Object sender, EventArgs e)
		{
			if (USER_PassUsrChanged != null)
			{
				USER_PassUsrChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_ActivoChanged(Object sender, EventArgs e)
		{
			if (USER_ActivoChanged != null)
			{
				USER_ActivoChanged(sender, e);
				ActualizarInstancia();
			}
		}
		protected void OnUSER_MailChanged(Object sender, EventArgs e)
		{
			if (USER_MailChanged != null)
			{
				USER_MailChanged(sender, e);
				ActualizarInstancia();
			}
		}
		
		#endregion

		#region Metodos
		
		public void Instanciar(ACEInstancia x_instancia)
		{
			switch (x_instancia)
			{
				case ACEInstancia.Consulta:
					this.m_nuevo = false;
					this.m_modificado = false;
					this.m_eliminado = false;
					break;
				case ACEInstancia.Nuevo:
					this.m_nuevo = true;
					this.m_modificado = false;
					this.m_eliminado = false;
					break;
				case ACEInstancia.Modificado:
					this.m_nuevo = false;
					this.m_modificado = true;
					this.m_eliminado = false;
					break;
				case ACEInstancia.Eliminado:
					this.m_nuevo = false;
					this.m_modificado = false;
					this.m_eliminado = true;
					break;
			}
		}
		public void ActualizarInstancia()
		{
			if (!m_nuevo)
			{
				if (!m_eliminado)
				{ Instanciar(ACEInstancia.Modificado); }
			}
		}
		
		#endregion
	}
}

